<?php
namespace app\api\controller;

use think\Controller;
use app\api\model\Sign;

class Signs extends Controller
{

    /**
     * 查询该用户的积分记录
     */
    public function index()
    {
        if (request()->isGet()){
            AjaxReturn('10020','传值方式错误');
            die;
        }
        if(request()->isPost()) {
            $userid = input('id');
            $sign = new Sign();
            $data = $sign->index($userid);
            if ($data == 0) {
                AjaxReturn('10013', '该用户暂无积分记录');
            } else {
                AjaxReturn('1', '成功', ['details' => $data]);
            }
        }
    }

    /**
     * 用户签到
     */
    public function add()
    {
        if (request()->isGet()){
            AjaxReturn('10020','传值方式错误');
            die;
        }
        if(request()->isPost()) {
            $userid = input('id');
            $sign = new Sign();
            $data = $sign->add($userid);
            if ($data == 0)  //签到失败
            {
                AjaxReturn('10014', '签到失败');
            } else  //签到成功返回新的数据
            {
                $datas = $sign->index($userid);
                AjaxReturn('1', '成功', ['details' => $datas]);
            }
        }
    }
}